/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2021年5月29日
 */
package com.massyframework.beanskin.runtime.framework;

import java.util.List;
import java.util.function.Predicate;

import com.massyframework.beanskin.Module;
import com.massyframework.beanskin.ModuleIdentifier;
import com.massyframework.beanskin.ModuleListener;
import com.massyframework.beanskin.ModuleRepository;
import com.massyframework.beanskin.RequireLibraryDescriptor;
import com.massyframework.beanskin.fragment.Fragment;

/**
 * 模块仓储封装器
 * @author huangkh
 *
 */
public abstract class ModuleRepositoryWrapper implements ModuleRepository {

	/**
	 * 
	 */
	public ModuleRepositoryWrapper() {
		
	}

	@Override
	public void addListener(ModuleListener listener) {
		this.getModuleRepository().addListener(listener);
	}

	@Override
	public Module<?> findModuleById(int id) {
		return this.getModuleRepository().findModuleById(id);
	}

	@Override
	public <T extends Module<?>> T findModuleById(int id, Class<T> requiredType) {
		return this.getModuleRepository().findModuleById(id, requiredType);
	}

	@Override
	public Module<?> findModuleByIdentifier(ModuleIdentifier identifier) {
		return this.getModuleRepository().findModuleByIdentifier(identifier);
	}

	@Override
	public <T extends Module<?>> T findModuleByIdentifier(ModuleIdentifier identifier, Class<T> requireType) {
		return this.getModuleRepository().findModuleByIdentifier(identifier, requireType);
	}

	@Override
	public Module<?> findByFilter(Predicate<Module<?>> filter) {
		return this.getModuleRepository().findByFilter(filter);
	}

	@Override
	public <T extends Module<?>> T findByFilter(Predicate<T> filter, Class<T> requireType) {
		return this.getModuleRepository().findByFilter(filter, requireType);
	}
	

	@Override
	public Module<?> findModuleWithOptimal(RequireLibraryDescriptor require) {
		return this.getModuleRepository().findModuleWithOptimal(require);
	}

	@Override
	public List<Module<?>> getModules() {
		return this.getModuleRepository().getModules();
	}

	@Override
	public List<Module<?>> getModules(Predicate<Module<?>> filter) {
		return this.getModuleRepository().getModules(filter);
	}

	@Override
	public <T extends Module<?>> List<T> getModules(Predicate<T> filter, Class<T> requireType) {
		return this.getModuleRepository().getModules(filter, requireType);
	}

	@Override
	public void removeListener(ModuleListener listener) {
		this.getModuleRepository().removeListener(listener);
	}

	@Override
	public int size() {
		return this.getModuleRepository().size();
	}
	
	@Override
	public boolean uninstall(Fragment fragment) {
		return this.getModuleRepository().uninstall(fragment);
	}

	protected abstract ModuleRepository getModuleRepository();
}
